package com.lhd._05mvcboot02.conmmon.exception;

import com.lhd._05mvcboot02.conmmon.response.JsonResult;
import com.lhd._05mvcboot02.conmmon.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lhd
 * @date 2024/4/26
 * @apiNote
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public JsonResult doThrowableException(Throwable ex) {
        log.debug("ex = " + ex);
        return new JsonResult(StatusCode.THROWABLE_ERROR,ex.getMessage());
    }
    @ExceptionHandler
    public JsonResult doHandleRuntimeException(RuntimeException ex) {
        log.debug("ex = " + ex);
        return new JsonResult(StatusCode.OPERATION_FAILED,ex.getMessage());
    }
}
